/*
 * Copyright 2010 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package noop.interpreter.config;

import com.google.inject.AbstractModule;
import com.google.inject.multibindings.Multibinder;

import java.io.File;
import java.io.PrintStream;

import noop.graph.CompositeModelVisitor;
import noop.graph.ModelVisitor;
import noop.interpreter.InterpreterVisitor;
import noop.persistence.ModelSerializer.SerializationFormat;
import static noop.persistence.ModelSerializer.SerializationFormat.XML;
import noop.persistence.XmlDiskCache;

/**
 * @author alexeagle@google.com (Alex Eagle)
 */
public class InterpreterModule extends AbstractModule {

  private final InterpreterOptions options;

  public InterpreterModule(InterpreterOptions options) {
    this.options = options;
  }

  @Override
  protected void configure() {
    bind(PrintStream.class).annotatedWith(Output.class).toInstance(System.out);
    bind(PrintStream.class).annotatedWith(Error.class).toInstance(System.err);
    bind(InterpreterOptions.class).toInstance(options);
    bind(SerializationFormat.class).toInstance(XML);
    bind(File.class).annotatedWith(XmlDiskCache.class)
        .toInstance(new File(System.getProperty("java.io.tmpdir")));
    bind(ModelVisitor.class).to(CompositeModelVisitor.class);
    Multibinder<ModelVisitor> visitors = Multibinder.newSetBinder(binder(), ModelVisitor.class);
    visitors.addBinding().to(InterpreterVisitor.class);
  }
}
